package com.yq588.demo.controller;

import com.yq588.demo.dao.SysUserMapper;
import com.yq588.demo.model.SysUser;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.view.json.MappingJackson2JsonView;

import javax.annotation.Resource;
import java.util.List;

@Controller
public class TestController {

    @Resource
    private SysUserMapper sysUserMapper;

    @RequestMapping("stringTest")
    @ResponseBody
    public String returnStr() {
        return "hello,即使是中文也可以";
    }

    @RequestMapping("user")
    @ResponseBody
    public ModelAndView user() {
        //ModelAndView modelAndView = new ModelAndView(new MappingJackson2JsonView());
        ModelAndView modelAndView = new ModelAndView("user");
        SysUser testBean = new SysUser();
        List<SysUser> sysUserList = sysUserMapper.selectAll();

        testBean.setRemark("测试实体");
        testBean.setUsername("asdfadsf");
        modelAndView.addObject("test", testBean);
        modelAndView.addObject("sysuser", sysUserList);
        return modelAndView;
    }
}